#include "StdAfx.h"
#include "MSLogon.h"

#define INITGUID
#define USES_IID_IMSLogon
#include <initguid.h>
#include <mapiguid.h>


#define log


CMSLogon::CMSLogon(LPINNEROBJ_T pObj) : m_pObj(pObj)
{
	InitializeCriticalSection( &m_csObj );
	LogEntry("CMSLogon::CMSLogon");
	if ( m_pObj ) {
		m_pObj->AddRef();
	}
}

CMSLogon::~CMSLogon(void)
{
	LogEntry("CMSLogon::~CMSLogon");
	DeleteCriticalSection( &m_csObj );
	if ( m_pObj ) {
		m_pObj->Release();
	}
}


//////////////////////////////////////////////////////////////////////////
// Implementation IUnknown
STDMETHODIMP CMSLogon::QueryInterface (REFIID riid, LPVOID * ppvObj)
{
	LogEntry("CMSLogon::QueryInterface");
	*ppvObj = NULL;

	if ( riid == IID_IMSLogon || riid == IID_IUnknown )	{
		*ppvObj = (LPVOID)this;
		AddRef();
		return S_OK;
	} else {
		return E_NOINTERFACE;
	}
}


STDMETHODIMP_(ULONG) CMSLogon::AddRef ()
{
	LogEntry( "CMSLogon::AddRef");
	EnterCriticalSection (&m_csObj);
	++m_cRef; ULONG ulCount = m_cRef;
	LeaveCriticalSection (&m_csObj);
	return ulCount;
}


STDMETHODIMP_(ULONG) CMSLogon::Release ()
{
	LogEntry( "CMSLogon::Release");
	EnterCriticalSection (&m_csObj);
	ULONG ulCount = --m_cRef;
	LeaveCriticalSection (&m_csObj);
	if (!ulCount){
		delete this;
	}
	return ulCount;
}



//////////////////////////////////////////////////////////////////////////
// IMSLogon
//
HRESULT CMSLogon::Advise(
						 ULONG cbEntryID,
						 LPENTRYID lpEntryID,
						 ULONG ulEventMask,
						 LPMAPIADVISESINK lpAdviseSink,
						 ULONG FAR * lpulConnection )
{
	static char * szFun = "CMSLogon::Advise";
	LogEntry( "CMSLogon::Advise method called");

	HRESULT hRes = S_OK;
	if ( m_pObj ) {
		hRes = m_pObj->Advise( cbEntryID, lpEntryID, ulEventMask, lpAdviseSink, lpulConnection );
	} else {
		hRes = MAPI_E_NO_SUPPORT;
	}
	return hRes;
}


HRESULT CMSLogon::CompareEntryIDs(
								  ULONG cbEntryID1,
								  LPENTRYID lpEntryID1,
								  ULONG cbEntryID2,
								  LPENTRYID lpEntryID2,
								  ULONG ulFlags,
								  ULONG FAR * lpulResult )
{
	static char * szFun = "CMSLogon::CompareEntryIDs";
	LogEntry( "CMSLogon::CompareEntryIDs method called");

	HRESULT hRes = S_OK;
	if ( m_pObj ) {
		hRes = m_pObj->CompareEntryIDs(cbEntryID1, lpEntryID1, cbEntryID2, lpEntryID2, ulFlags, lpulResult);
	}else {
		hRes = MAPI_E_NO_SUPPORT;
	}
	return hRes;
}


HRESULT CMSLogon::GetLastError( HRESULT hResult, ULONG ulFlags, LPMAPIERROR FAR * lppMAPIError )
{
	static char * szFun = "CMSLogon::GetLastError";
	LogEntry( "CMSLogon::GetLastError method called");

	HRESULT hRes = S_OK;
	if ( m_pObj ) {
		hRes = m_pObj->GetLastError(hResult, ulFlags, lppMAPIError );
	} else {
		hRes = MAPI_E_NO_SUPPORT;
	}
	return hRes;
}



HRESULT CMSLogon::Logoff( ULONG FAR * lpulFlags )
{
	static char * szFun = "CMSLogon::Logoff";
	return S_OK;
}



HRESULT CMSLogon::OpenEntry(
							ULONG cbEntryID,
							LPENTRYID lpEntryID,
							LPCIID lpInterface,
							ULONG ulFlags,
							ULONG FAR * lpulObjType,
							LPUNKNOWN FAR * lppUnk )
{
	static char * szFun = "CMSLogon::OpenEntry";
	LogEntry( "CMSLogon::OpenEntry method called");

	HRESULT hRes = S_OK;
	if ( m_pObj ) {
		hRes = m_pObj->OpenEntry( cbEntryID, lpEntryID, lpInterface, ulFlags, lpulObjType, lppUnk);
	} else {
		hRes = MAPI_E_NO_SUPPORT;
	}

	return hRes;
}



HRESULT CMSLogon::OpenStatusEntry(
								  LPCIID lpInterface,
								  ULONG ulFlags,
								  ULONG FAR * lpulObjType,
								  LPVOID FAR * lppEntry )
{
	static char * szFun = "CMSLogon::OpenStatusEntry";
	return MAPI_E_NO_SUPPORT;
}


HRESULT CMSLogon::Unadvise( ULONG ulConnection )
{
	static char * szFun = "CMSLogon::Unadvise";
	LogEntry( "CMSLogon::Unadvise method called");

	HRESULT hRes = S_OK;
	if ( m_pObj ) {
		hRes = m_pObj->Unadvise( ulConnection );
	} else {
		hRes = MAPI_E_NO_SUPPORT;
	}
	return hRes;
}
